package com.yunji.web.base;

import com.yunji.aggregate.model.vo.base.SiteLocationStatisticsVO;
import com.yunji.aggregate.service.BaseAggregateService;
import com.yunji.base.business.SiteLocationBusiness;
import com.yunji.base.dto.DeployStaffDTO;
import com.yunji.base.dto.SiteLocationDTO;
import com.yunji.aggregate.model.dto.analysis.SiteLocationStatisticsParam;
import com.yunji.base.vo.DeployStaffVO;
import com.yunji.base.vo.SiteLocationVO;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "管理端-点位信息")
@RequestMapping("/site/location")
public class SiteLocationController {

    @Resource
    private SiteLocationBusiness business;

    @Resource
    private BaseAggregateService aggregateService;

    @ApiOperation("点位列表")
    @GetMapping("/list")
    public Response<List<SiteLocationStatisticsVO>> list(@Valid SiteLocationStatisticsParam param){
        return ResponseHelper.successWithPage(aggregateService.getSiteLocationVOList(param));
    }

    @ApiOperation("新增点位")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermi('container:area:add')")
    public Response<Long> create(@RequestBody @Valid SiteLocationDTO dto){
        return ResponseHelper.success(business.create(dto));
    }

    @ApiOperation("获取详情")
    @GetMapping("/getInfo/{id}")
    public Response<SiteLocationVO> getInfo(@PathVariable Long id){
        return ResponseHelper.success(business.getInfo(id));
    }

    @ApiOperation("修改点位")
    @PutMapping("/update")
    @PreAuthorize("@ss.hasPermi('container:area:edit')")
    public Response<String> update(@RequestBody @Valid SiteLocationDTO dto){
        business.update(dto);
        return ResponseHelper.success("修改成功");
    }

    @ApiOperation("删除点位")
    @DeleteMapping("/delete/{ids}")
    @PreAuthorize("@ss.hasPermi('container:area:remove')")
    public Response<String> delete(@PathVariable Long... ids){
        business.delete(ids);
        return ResponseHelper.success("删除成功");
    }

    @ApiOperation("分配员工")
    @PostMapping("/deployStaff")
    @PreAuthorize("@ss.hasPermi('container:area:staff')")
    public Response<String> deployStaff(@RequestBody DeployStaffDTO dto){
        business.deployStaff(dto);
        return ResponseHelper.success("分配成功");
    }

    @ApiOperation("查询分配员工ID")
    @GetMapping("/getDeployStaffIds/{id}")
    public Response<List<DeployStaffVO>> getDeployStaffIds(@PathVariable Long id){
        return ResponseHelper.success(business.getDeployStaffIds(id));
    }

    /*------------------------------------搜索栏----------------------------------*/

    @ApiOperation("点位名称匹配搜索")
    @GetMapping("/searchLocationName")
    public Response<List<String>> searchLocationName(@RequestParam("locationName") String locationName) {
        return ResponseHelper.successWithPage(aggregateService.searchLocationName(locationName));
    }

    @ApiOperation("代理名称匹配搜索")
    @GetMapping("/searchAgentName")
    public Response<List<String>> searchAgentName(@RequestParam("agentName") String agentName) {
        return ResponseHelper.successWithPage(aggregateService.searchAgentName(agentName));
    }

    @ApiOperation("点位名称匹配搜索")
    @GetMapping("/searchSiteName")
    public Response<List<String>> searchSiteName(@RequestParam("siteName") String siteName) {
        return ResponseHelper.successWithPage(aggregateService.searchSiteName(siteName));
    }

}

